//  入口文件  也就是模块的接口文件     目的是： 暴露给外部模块使用’
import { request } from './core' //引入get 和 post
import URL from './url' //引入登录请求的url
import METHODS from './methods' //请求方式 （引入未经定义的魔法值）


/*
路径
https://api.it120.cc/small4/user/m/login?deviceId=007&deviceName=monkey
https://api.it120.cc/small4/user/m/register
https://api.it120.cc/small4/user/shipping-address/detail
*/

//封装一个对象
const APLlient = {
    //将对象注入Vue全局  这种方法可以在main.js里写成Vue.use（APL）
    install(Vue) {
        Vue.prototype.$APL = this;
    },

    // 登录接口 login
    /**
     * 
     * @param {*} mobile //参数1
     * @param {*} password  //参数2
     */
    login(mobile, password) { return request(METHODS.POST, URL.LOGIN+`&mobile=${mobile}&pwd=${password}`) }, //使用login


    /**
     * 
     * @param {*} mobile    //参数1
     * @param {*} password  //参数2
     * @param {*} nickname  //参数3
     * @param {*} code      //参数4
     */
    register(mobile, password, nickname, code) { return request(METHODS.GET, URL.REGISTER, { mobile: mobile, pwd: password, code: code, nick: nickname }) },

    getStoreList(mobile, password) {
        return request(METHODS.GET, URL.STOPLIST);
    },

    Banner() { return request(METHODS.GET, URL.BANNER) },//轮播

    KANJIA(params) { return request(METHODS.GET, URL.KANJIA,params) }, //砍价

    NEWSLIST() { return request(METHODS.GET, URL.NEWSLIST) },//精选专题

    DETAIL(params) { return request(METHODS.GET, URL.DETAIL, params) }, //严选列表

    KANJIAINFO(params, kjid, joiner) { return request(METHODS.POST, URL.KANJIAINFO, params, { kjid: kjid, joiner: joiner }) }, //砍价详情

    GOODSPOST(params) { return request(METHODS.POST, URL.GOODSPOST, params) },

    DETAILPOST(id) { return request(METHODS.GET, URL.DETAILPOST, {params:{id:id}}) }, //商品详情

    REQUTATION(goodsId) { return request(METHODS.GET, URL.REQUTATION+`?goodsId=${goodsId}`) },

    SHOPLIST() { return request(METHODS.GET, URL.STOPLIST) },
}

export default APLlient //导出一个对象